<template>
  <j-modal
    :title="`设置中标候选人`"
    :width="1000"
    :visible="visible"
    switchFullscreen
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>
    <a-card :bordered="false"> 
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{ x: true }"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="false"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange"
        >
          <span slot="action" slot-scope="text, record">
            <!-- {{ record.exZbcandidateDetailedId }} -->
            <a-switch v-model="record.isCandidate" @change="onChange(record)" size="small" />
          </span>
        </a-table>
      </div>
    </a-card>
  </j-modal>
</template>

<script>
import '@assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@comp/dict/JDictSelectUtil'
import { httpAction, getAction } from '@/api/manage'
import Footer from '../user/register/footer.vue'

export default {
  name: 'ExZbwjBidEvaluationConfigList',
  mixins: [JeecgListMixin, mixinDevice],
  components: { Footer },
  data() {
    return {
      description: '招标候选人列表',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '投标人',
          align: 'center',
          dataIndex: 'bidderName',
        },
        {
          title: '投标报价',
          align: 'center',
          dataIndex: 'bidPrice',
        },
        {
          title: '最终报价',
          align: 'center',
          dataIndex: 'lastPrice',
        },
        {
          title: '工期',
          align: 'center',
          dataIndex: 'limiteTime',
        },
        {
          title: '商务标得分',
          align: 'center',
          dataIndex: 'businessPartScore',
        },
        {
          title: '技术标得分',
          align: 'center',
          dataIndex: 'techPartScore',
        },
        {
          title: '综合标得分',
          align: 'center',
          dataIndex: 'compositeScore',
        },
        {
          title: '其他得分',
          align: 'center',
          dataIndex: 'otherScore',
        },
        {
          title: '最终得分',
          align: 'center',
          dataIndex: 'finalScore',
        },
        {
          title: '排名',
          align: 'center',
          dataIndex: 'rank',
        },
        {
          title: '设置中标人',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/exPingbiao/exTbcompanyScore/list', 
        add: '/exPingbiao/exZbcandidateDetailed/add',
        del: '/exPingbiao/exZbcandidateDetailed/delete',
      },
      dictOptions: {},
      superFieldList: [],
      disableMixinCreated: true,
      projectId: null,
      exSectionList: [],
      visible: false,
    }
  },
  created() {
    this.getSuperFieldList()
    this.projectId = this.$route.query.projectId
    this.projectName = this.$route.query.projectName
    this.getProjectSection()
    //初始化字典配置 在自己页面定义
    this.initDictConfig()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    edit(record) {
      alert(record.bidSectionId)
    },
    searchQuery() {
      if (
        this.queryParam.bidSectionId == '' ||
        this.queryParam.bidSectionId == null ||
        this.queryParam.bidSectionId == undefined
      ) {
        this.$message.warning('请选择标段')
        return
      }
      this.loadData()
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      this.superFieldList = fieldList
    },
    getProjectSection() {
      this.exSectionList = []
      getAction('/exProject/exSection/listAll', { projectId: this.projectId })
        .then((res) => {
          if (res.success) {
            var result = res.result
            for (let i = 0; i < result.length; i++) {
              this.exSectionList.push(result[i])
            }
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    show(record) {
      this.visible = true
      this.queryParam.bidSectionId = record.bidSectionId
      this.searchQuery()
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    onChange(record) {
      var that = this
      var param = Object.assign({}, record)
      var httpUrl
      var method
      if (record.isCandidate) {
        param['winCandidateName'] = param.bidderName
        param['sectionid'] = param.bidSectionId
        httpUrl = this.url.add
        method = 'post'
      } else {
        httpUrl = this.url.del+'?id='+param.exZbcandidateDetailedId
        method = 'delete'
        param['id'] = param.exZbcandidateDetailedId
      }
      that.loading = true
      httpAction(httpUrl, param, method)
        .then((res) => {
          if (res.success) {
            this.$message.success('操作成功')
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
